<template>
	<uni-popup ref="popup">
		<view class="popup-content">
			<uni-forms ref="valiForm" :rules="rules" :modelValue="formData" label-width="50">
				<uni-forms-item label="发票抬头" required name="header">
					<uni-easyinput v-model="formData.header" placeholder="请输入企业名称" />
				</uni-forms-item>
				<uni-forms-item label="企业税号" required name="tin">
					<uni-easyinput v-model="formData.tin" placeholder="请输入企业税号" />
				</uni-forms-item>
				<uni-forms-item label="公司地址" required name="address">
					<uni-easyinput v-model="formData.address" placeholder="请输入公司地址" />
				</uni-forms-item>
				<uni-forms-item label="联系方式" required name="tel">
					<uni-easyinput v-model="formData.tel" placeholder="请输入联系方式" />
				</uni-forms-item>
				<uni-forms-item label="开户银行" required name="opening_bank">
					<uni-easyinput v-model="formData.opening_bank" placeholder="请输入开户银行" />
				</uni-forms-item>
				<uni-forms-item label="银行账号" required name="bank_account">
					<uni-easyinput v-model="formData.bank_account" placeholder="请输入银行账号" />
				</uni-forms-item>
			</uni-forms>
			<view class="btn" @click="submit">
				确定
			</view>
		</view>
	</uni-popup>
</template>

<script>
	export default {
		data() {
			return {
				formData: {
					orderId:'',
					type:'company',
					header: '',
					tin: '',
					address: '其他',
					tel: '其他',
					opening_bank: '其他',
					bank_account: '其他',
				},
				// 校验规则
				rules: {
					header: {
						rules: [{
							required: true,
							errorMessage: '请输入企业名称'
						}]
					},
					tin: {
						rules: [{
							required: true,
							errorMessage: '请输入企业税号'
						}]
					},
				}
			}
		},
		props: {
			orderId: {
				default: ''
			},
		},
		methods: {
			open() {
				this.$refs.popup.open()
			},
			close() {
				this.$refs.popup.close()
			},
			submit() {
				this.$refs.valiForm.validate().then(res => {
					// console.log('success', res);
					if(!res.header)
					{
						uni.showToast({
							title:'请输入公司名称',
							icon:'none'
						})
						return false
					}
					if(!res.tin)
					{
						uni.showToast({
							title:'请输入纳税人识别号',
							icon:'none'
						})
						return false
					}
					this.formData.orderId = this.orderId
					this.$post(`/order/orderInvoice`, this.formData).then(res => {
							if(res.code === 200)
							{
								this.$toast("提交申请成功")
							}else{
								this.$toast(res.msg)
							}
							
							this.close()
						})
					
					
				
				}).catch(err => {
					console.log('err', err);
				})
			},
		}
	}
</script>

<style lang="scss">
	.popup-content {
		background-color: #fff;
		padding: 60rpx;
		border-radius: 30rpx;
		width: 90vw;

		.text {
			font-weight: bold;
			font-size: 56rpx;
		}

		.btn {
			margin: 0 auto;
			margin-top: 80rpx;
			width: 250rpx;
			line-height: 90rpx;
			border-radius: 25px;
			background-color: $assist-color2;
			// color: #fff;
			border: 2rpx solid #A4ADB3;
			font-size: 36rpx;
			text-align: center;
		}
	}
</style>